package com.softer.wxzj.common.flow.util;

import com.softer.wxzj.common.enums.NumberEnum;
import com.softer.wxzj.common.flow.enums.FlowStateEnum;
import com.softer.wxzj.common.util.DateUtils;
import com.softer.wxzj.common.util.ShiroUserUtil;
import com.softer.wxzj.entity.base.BaseEntity;
import org.springframework.stereotype.Component;

import java.util.Map;

/**
 * 用于审核
 *
 * @author wxr
 */
@Component
public class Result {

    /**
     * 处理审核结果
     *
     * @param auditState 状态
     * @param baseEntity 审核实体
     */
    public void result(String auditState, BaseEntity baseEntity) {
        //终审成功，修改业务表
        if (FlowStateEnum.PASS.getState().equals(auditState)) {
            //flow_state填写auditState
            baseEntity.setFlowState(auditState);
            baseEntity.setRecDate(DateUtils.getNow());
            baseEntity.setModifier(ShiroUserUtil.getUserName());
            baseEntity.setRecOper(ShiroUserUtil.getUserName());
        } else if (FlowStateEnum.VETO.getState().equals(auditState)) {
            //flow_state填写auditState
            baseEntity.setFlowState(auditState);
        } else if (FlowStateEnum.BACK.getState().equals(auditState)) {
            //flow_state填写auditState
            baseEntity.setFlowState(auditState);
        }
    }

    /**
     * 查询审核的数据条件封装
     *
     * @param map
     * @param baseEntity
     * @return
     */
    public BaseEntity select(Map<String, String> map, BaseEntity baseEntity) {
        // 从审批流提取的业务id集合
        baseEntity.setId(map.get("id"));
        // 用户绑定的区域
        baseEntity.setZoneCode(map.get("zoneCode"));
        //业务表的审核状态 1审核中
        baseEntity.setFlowState(String.valueOf(NumberEnum.ONE.getNum()));

        return baseEntity;
    }
    /**
     * 查询审核的数据条件封装
     *
     * @param map
     * @param baseEntity
     * @return
     */
    public BaseEntity selectParm(Map<String, String> map, BaseEntity baseEntity) {
        // 从审批流提取的业务id集合
        baseEntity.setId(map.get("id"));
        // 用户绑定的区域
        baseEntity.setLoginZoneCode(map.get("zoneCode"));
        //业务表的审核状态 1审核中
        baseEntity.setFlowState(String.valueOf(NumberEnum.ONE.getNum()));
        return baseEntity;
    }

}
